package com.xxl.job.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xxl.job.admin.core.model.XxlJobLog;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * job log
 *
 * @author xuxueli 2016-1-12 18:03:06
 */
@Mapper
public interface XxlJobLogDao extends BaseMapper<XxlJobLog> {

    /**
     * exist jobId not use jobGroup, not exist use jobGroup
     *
     * @param offset offset
     * @param pageSize pageSize
     * @param jobGroup jobGroup
     * @param jobId jobId
     * @param triggerTimeStart triggerTimeStart
     * @param triggerTimeEnd triggerTimeEnd
     * @param logStatus logStatus
     * @return List
     */
    List<XxlJobLog> pageList(@Param("offset") int offset,
            @Param("pageSize") int pageSize,
            @Param("jobGroup") int jobGroup,
            @Param("jobId") int jobId,
            @Param("triggerTimeStart") Date triggerTimeStart,
            @Param("triggerTimeEnd") Date triggerTimeEnd,
            @Param("logStatus") int logStatus);

    int pageListCount(@Param("offset") int offset,
            @Param("pagesize") int pagesize,
            @Param("jobGroup") int jobGroup,
            @Param("jobId") int jobId,
            @Param("triggerTimeStart") Date triggerTimeStart,
            @Param("triggerTimeEnd") Date triggerTimeEnd,
            @Param("logStatus") int logStatus);

    XxlJobLog load(@Param("id") long id);

    long save(XxlJobLog xxlJobLog);

    int updateTriggerInfo(XxlJobLog xxlJobLog);

    int updateHandleInfo(XxlJobLog xxlJobLog);

    int delete(@Param("jobId") int jobId);

    int triggerCountByHandleCode(@Param("handleCode") int handleCode);

    List<Map<String, Object>> triggerCountByDay(@Param("from") Date from,
            @Param("to") Date to);

    int clearLog(@Param("jobGroup") int jobGroup,
            @Param("jobId") int jobId,
            @Param("clearBeforeTime") Date clearBeforeTime,
            @Param("clearBeforeNum") int clearBeforeNum);

    List<Long> findFailJobLogIds(@Param("pageSize") int pageSize);

    int updateAlarmStatus(@Param("logId") long logId,
            @Param("oldAlarmStatus") int oldAlarmStatus,
            @Param("newAlarmStatus") int newAlarmStatus);

}
